﻿
@{
    ViewBag.Title = "AddNew";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section class="layui-larry-box">
    <div class="larry-personal">
        <header class="larry-personal-tit">
            <span>添加字典键值对</span>
        </header><!-- /header -->

        <div class="larry-personal-body clearfix">
            <form class="layui-form col-lg-5" action="" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">类型名</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" name="typeName" autocomplete="off" class="layui-input" placeholder="请输入类型名">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" name="name" autocomplete="off" class="layui-input" placeholder="请输入名称">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="addNew">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>

@section FooterScript{
    <script src="~/common/layui/layui.js"></script>
    <script type="text/javascript">
        // 定义一个渲染方法
        function renderForm() {
            layui.use('form', function () {
                var form = layui.form();//高版本建议把括号去掉，有的低版本，需要加()
                form.render();
            });
        }

  

      
        layui.use(['jquery', 'layer', 'element', 'laypage', 'form'], function () {
            window.jQuery = window.$ = layui.jquery;
            window.layer = layui.layer;
            var element = layui.element(),
                laypage = layui.laypage;
            var form = layui.form();

            //此处的addNew代码中提交按钮的 lay-filter属性
            form.on("submit(addNew)", function (data) {

                var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });

                var formData = $(".layui-form").serialize();    //表单数据

                $.ajax({
                    url: "/IdName/AddNew",
                    method: "post",
                    dataType: "json",
                    data: formData,
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg("添加成功", {
                                icon: 1, time: 1000, end: function () {
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });



                        } else {
                            layer.msg("添加失败:" + res.errorMsg, {
                                icon: 5, time: 2000, end: function () {
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        layer.msg("网络请求失败", {
                            icon: 5, time: 2000, end: function () {
                                top.layer.close(index);
                                layer.closeAll("iframe");
                                //刷新父页面
                                parent.location.reload();
                            }
                        });
                    }
                });

                return false;
            })
        });
    </script>

}
